package com.vito.framework.system.user.model;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.vito.framework.base.model.Entity;
import com.vito.framework.system.role.model.RoleBean;
import com.vito.util.UploadUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Date;
import java.util.List;

@Data
@EqualsAndHashCode(callSuper = true)
@TableName("sys_user")
@ApiModel(value = "sys_user对象", description = "系统用户表")
public class UserBean extends Entity<UserBean> {
    /**
     * 保存到session必须序列化
     */
    private static final long serialVersionUID = 8985675818645729662L;

    @TableId("user_id")
    @ApiModelProperty("用户标识")
    private String userId;

    @TableField("user_name")
    @ApiModelProperty("用户姓名")
    private String userName;

    @TableField("account")
    @ApiModelProperty("用户账号")
    private String account;

    @TableField("password")
    @ApiModelProperty("用户密码")
    private String password;

    @TableField(exist = false)
    @ApiModelProperty("用户原密码")
    private String oldPassword;

    @TableField("org_id")
    @ApiModelProperty("机构编码")
    private String orgId;

    @TableField("dept_id")
    @ApiModelProperty("所属部门ID")
    private String deptId;

    @TableField(exist = false)
    @ApiModelProperty("所属部门")
    private String deptName;

    @TableField("head_img")
    @ApiModelProperty("用户头像")
    private String headImg;

    @TableField(exist = false)
    @ApiModelProperty("用户头像")
    private String headImgPath;

    @TableField(exist = false)
    @ApiModelProperty("用户头像")
    private String headImgPathShow;

    @TableField(exist = false)
    @ApiModelProperty("确认密码")
    private String makeSurePassword;

    @TableField(exist = false)
    @ApiModelProperty("登录时间")
    private Date loginTime;

    @TableField(exist = false)
    @ApiModelProperty("登录IP")
    private String ip;

    @TableField("sex")
    @ApiModelProperty("性别")
    private String sex;

    @TableField("mobile")
    @ApiModelProperty("手机号")
    private String mobile;

    @TableField("tel")
    @ApiModelProperty("座机号")
    private String tel;

    @TableField("email")
    @ApiModelProperty("Email")
    private String email;

    @TableField("post")
    @ApiModelProperty("邮编")
    private String post;

    @TableField("user_type")
    @ApiModelProperty("用户类型 0超级管理员 1省级管理员 2市级管理员")
    private String userType;

    @TableField(exist = false)
    @ApiModelProperty("用户类型 0超级管理员 1省级管理员 2市级管理员")
    private String userTypeName;

    @TableField(exist = false)
    @ApiModelProperty("机构名称")
    private String orgName;

    @TableField(exist = false)
    @ApiModelProperty("机构类型")
    private String orgType;

    @TableField(exist = false)
    @ApiModelProperty("机构级别")
    private String orgLevel;

    @TableField("status")
    @ApiModelProperty("用户状态 0正常 1停用")
    private String status;

    @TableField(exist = false)
    @ApiModelProperty("用户状态 0正常 1停用")
    private String statusName;

    @TableField(exist = false)
    @ApiModelProperty("级联城市代码")
    private String cityCodeCascade;

    @TableField(exist = false)
    @ApiModelProperty("级联城市名称")
    private String cityNameCascade;

    @TableField(exist = false)
    @ApiModelProperty("管辖地市")
    private String cityCode;

    @TableField(exist = false)
    @ApiModelProperty("管辖地市")
    private String cityName;

    @TableField(exist = false)
    @ApiModelProperty("管辖区域")
    private String countyCode;

    @TableField(exist = false)
    @ApiModelProperty("管辖区域")
    private String countyName;

    @TableField(exist = false)
    @ApiModelProperty("员工卡号")
    private String cardNum;

    @TableField("operator")
    @ApiModelProperty("操作人")
    private String operator;

    @TableField("opdate")
    @ApiModelProperty("操作时间")
    private String opdate;

    @TableField(exist = false)
    @ApiModelProperty("角色名称集合")
    private String roleNames;

    @TableField(exist = false)
    @ApiModelProperty("旧账号")
    private String oldAccount;

    @TableField(exist = false)
    @ApiModelProperty("角色id集合")
    private String[] roleIds;

    @TableField(exist = false)
    @ApiModelProperty("机构名称")
    private List<String> roleIdsList;

    @TableField(exist = false)
    @ApiModelProperty("角色对象")
    private List<RoleBean> roleSet;

    public String getHeadImgPathShow() {
        return UploadUtil.replacePath(headImgPath);
    }

    public void setUserType(String userType) {
        this.userType = userType;
        if ("0".equals(userType)) {
            this.userTypeName = "超级管理员";
        } else if ("1".equals(userType)) {
            this.userTypeName = "省级管理员";
        } else if ("2".equals(userType)) {
            this.userTypeName = "市级管理员";
        }
    }

    public void setStatus(String status) {
        this.status = status;
        if ("1".equals(status)) {
            this.statusName = "正常";
        } else if ("0".equals(status)) {
            this.statusName = "暂停";
        }
    }
}
